<?php

namespace models\DAO;

use models\Exception\DAO\ModelDriverException;
use models\Exception\DAO\ModelException;
use models\Exception\DAO\ModelReflectionException;
use models\Exception\DAO\ModelSqlException;


/**
 * @SWG\Swagger(
 *     @SWG\Definition(
 *          type="object",
 *          definition="tbkorderSingleData",
 *          required={"errno", "errmsg", "data"},
 *          @SWG\Property(property="errno", type="integer", format="int32", description="编码"),
 *          @SWG\Property(property="errmsg", type="string", format="string", description="错误提示信息"),
 *          @SWG\Property(property="result", type="object", ref="#/definitions/tbkorderSingleObj")
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="tbkorderSingleObj",
 *          @SWG\Property(property="data", type="object", ref="#/definitions/tbkorderSingle")
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="tbkorderListData",
 *          required={"errno", "errmsg", "result"},
 *          @SWG\Property(property="errno", type="integer", format="int32", description="编码"),
 *          @SWG\Property(property="errmsg", type="string", format="string", description="错误提示信息"),
 *          @SWG\Property(property="result", ref="#/definitions/tbkorderListObj"),
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="tbkorderListObj",
 *          @SWG\Property(property="data", type="object", ref="#/definitions/tbkorderData"),
 *          @SWG\Property(property="meta", ref="#/definitions/meta")
 *     ),
 *     @SWG\Definition(
 *          type="array",
 *          definition="tbkorderData",
 *          @SWG\Items(
 *              title="data", ref="#/definitions/tbkorderSingle"
 *          )
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="tbkorderSingle",
 *          @SWG\Property(property="click_time", type="string", format="string",  description="点击时间"),
 *          @SWG\Property(property="create_time", type="string", format="string",  description="创建时间"),
 *          @SWG\Property(property="pay_time", type="string", format="string",  description="付款时间"),
 *          @SWG\Property(property="settlement_time", type="string", format="string",  description="结算时间"),
 *          @SWG\Property(property="tb_pay_time", type="string", format="string",  description="淘宝付款时间"),
 *          @SWG\Property(property="item_id", type="string", format="string",  description="商品ID"),
 *          @SWG\Property(property="title", type="string", format="string",  description="商品标题"),
 *          @SWG\Property(property="image", type="string", format="string",  description="商品主图"),
 *          @SWG\Property(property="aliwangwang", type="string", format="string",  description="掌柜旺旺"),
 *          @SWG\Property(property="shop_title", type="string", format="string",  description="所属店铺"),
 *          @SWG\Property(property="total", type="integer", format="int32",  description="商品数"),
 *          @SWG\Property(property="price", type="string", format="string",  description="商品单价"),
 *          @SWG\Property(property="category", type="string", format="string",  description="类目名称"),
 *          @SWG\Property(property="order_sn", type="string", format="string",  description="淘宝订单编号"),
 *          @SWG\Property(property="sub_order_sn", type="string", format="string",  description="淘宝子订单号"),
 *          @SWG\Property(property="order_stats", type="integer", format="int32",  description="订单状态(1为订单失败,2为订单付款,3为订单成功,4为订单结算,5为已为会员添加余额,默认0)"),
 *          @SWG\Property(property="type", type="string", format="string",  description="订单类型"),
 *          @SWG\Property(property="payment_amount", type="string", format="string",  description="付款金额"),
 *          @SWG\Property(property="settlement_amount", type="string", format="string",  description="结算金额"),
 *          @SWG\Property(property="commission_ratio", type="string", format="string",  description="佣金比率"),
 *          @SWG\Property(property="commission", type="string", format="string",  description="佣金金额"),
 *          @SWG\Property(property="subsidy_ratio", type="string", format="string",  description="补贴比率"),
 *          @SWG\Property(property="subsidy_amount", type="string", format="string",  description="补贴金额"),
 *          @SWG\Property(property="subsidy_type", type="string", format="string",  description="补贴类型"),
 *          @SWG\Property(property="income_ratio", type="string", format="string",  description="收入比率"),
 *          @SWG\Property(property="split_ratio", type="string", format="string",  description="分成比率"),
 *          @SWG\Property(property="income", type="string", format="string",  description="提成"),
 *          @SWG\Property(property="tech_service_rate", type="string", format="string",  description="技术服务费率"),
 *          @SWG\Property(property="tech_service_fee", type="string", format="string",  description="技术服务费"),
 *          @SWG\Property(property="effect_estimates", type="string", format="string",  description="付款预估收入"),
 *          @SWG\Property(property="estimated_income", type="string", format="string",  description="结算预估收入"),
 *          @SWG\Property(property="source_id", type="integer", format="int32",  description="来源媒体ID"),
 *          @SWG\Property(property="source_name", type="string", format="string",  description="来源媒体名称"),
 *          @SWG\Property(property="ad_id", type="integer", format="int32",  description="广告位ID"),
 *          @SWG\Property(property="ad_name", type="string", format="string",  description="广告位名称"),
 *          @SWG\Property(property="transaction_platform", type="string", format="string",  description="成交平台"),
 *          @SWG\Property(property="created_at", type="string", format="string",  description="导入系统时间"),
 *          @SWG\Property(property="member_id", type="integer", format="int32",  description="会员编号"),
 *          @SWG\Property(property="stats_name", type="string", format="string",  description="状态中文"),
 *          @SWG\Property(property="rebate", type="float", format="float",  description="返利金额"),
 *          @SWG\Property(property="parent_rebate", type="float", format="float",  description="晒单会员的上级返利"),
 *          @SWG\Property(property="grand_parent_rebate", type="float", format="float",  description="晒单会员的上上级返利"),
 *     )
 * )
 */
class TbkorderModel extends BaseModel{

    /**
     * 淘宝订单编号
     */
    public $order_sn = null;

    /**
     * 点击时间
     */
    public $click_time = null;

    /**
     * 创建时间
     */
    public $create_time = null;

    /**
     * 付款时间
     */
    public $pay_time = null;

    /**
     * 结算时间
     */
    public $settlement_time = null;

    /**
     * 淘宝付款时间
     */
    public $tb_pay_time = null;

    /**
     * 商品ID
     */
    public $item_id = null;

    /**
     * 商品标题
     */
    public $title = null;

    /**
     * 商品主图
     */
    public $image = null;

    /**
     * 掌柜旺旺
     */
    public $aliwangwang = null;

    /**
     * 所属店铺
     */
    public $shop_title = null;

    /**
     * 商品数
     */
    public $total = null;

    /**
     * 商品单价
     */
    public $price = null;

    /**
     * 类目名称
     */
    public $category = null;

    /**
     * 淘宝子订单号
     */
    public $sub_order_sn = null;

    /**
     * 订单状态(1为订单失败,2为订单付款,3为订单成功,4为订单结算,默认0)
     */
    public $order_stats = null;

    /**
     * 订单类型
     */
    public $type = null;

    /**
     * 付款金额
     */
    public $payment_amount = null;

    /**
     * 结算金额
     */
    public $settlement_amount = null;

    /**
     * 佣金比率
     */
    public $commission_ratio = null;

    /**
     * 佣金金额
     */
    public $commission = null;

    /**
     * 补贴比率
     */
    public $subsidy_ratio = null;

    /**
     * 补贴金额
     */
    public $subsidy_amount = null;

    /**
     * 补贴类型
     */
    public $subsidy_type = null;

    /**
     * 收入比率
     */
    public $income_ratio = null;

    /**
     * 分成比率
     */
    public $split_ratio = null;

    /**
     * 提成
     */
    public $income = null;

    /**
     * 技术服务费率
     */
    public $tech_service_rate = null;

    /**
     * 技术服务费
     */
    public $tech_service_fee = null;

    /**
     * 付款预估收入
     */
    public $effect_estimates = null;

    /**
     * 结算预估收入
     */
    public $estimated_income = null;

    /**
     * 来源媒体ID
     */
    public $source_id = null;

    /**
     * 来源媒体名称
     */
    public $source_name = null;

    /**
     * 广告位ID
     */
    public $ad_id = null;

    /**
     * 广告位名称
     */
    public $ad_name = null;

    /**
     * 成交平台
     */
    public $transaction_platform = null;

    /**
     * 导入系统时间
     */
    public $created_at = null;

    /**
     * 晒单会员返利
     */
    public $rebate = null;

    /**
     * 晒单会员的上级返利
     */
    public $parent_rebate = null;

    /**
     * 晒单会员的上上级返利
     */
    public $grand_parent_rebate = null;

    /**
     * 会员编号
     */
    public $member_id = null;
    /**
     * DAO对象
     */
    public $obj = '';

    /**
     * DAO对象数组
     */
    public $data = [];

    /**
     * 翻页对象
     */
    public $meta = null;

    /**
     * 当前页
     */
    public $page = 1;

    /**
     * 每页显示条数
     */
    public $page_size = 10;

    /**
     * 主键数组
     */
    public $primary_key_arr = ["order_sn"];

    /**
     * 自增字段数组
     */
    public $auto_increment_key_arr = [];

    /**
     * 唯一字段
     */
    public $unique_key_arr = '';

    /**
     * 单例实例
     */
    static public $instance = null;

    /**
     * @return TbkorderModel|null
     * @throws ModelSqlException
     */
    static public function getInstance() {
        if(is_null(self::$instance)){
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * TbkorderModel constructor.
     * @throws ModelSqlException
     */
    public function __construct() {
        parent::__construct(str_replace("Model", "", substr(get_class($this), strrpos(get_class($this), "\\")+1)));
        $this->meta = new \stdClass();
    }

    /**
     * @throws ModelException
     */
    public function __clone() {
        throw new ModelException(
            str_replace('%s', get_class($this), ModelException::INSTANCE_NOT_ALLOW_TO_CLONE), ModelException::INSTANCE_NOT_ALLOW_TO_CLONE_NO);
    }

    public function __destruct() {
        self::$instance = null;
    }

    /**
     * set属性
     *
     * __set.
     * @param string $name 参数名
     * @param string $value 参数值
     * @return $this
     */
    public function __set($name = "", $value = "") {
        $this->$name = $value;
        return $this;
    }

    /**
     * get属性
     *
     * __get.
     * @param string $name 参数名
     * @return mixed
     */
    public function __get($name = "") {
        return  $this->$name ;
    }

    /**
     * 创建tbkorderModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function insert() {
        return $this->insertRecord();
    }

    /**
     * 编辑tbkorderModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function update() {
        return $this->updateRecord();
    }

    /**
     * 删除tbkorderModel，需先指定主键
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function delete() {
        return $this->deleteRecord();
    }

    /**
     * 根据主键查询tbkorderModel，获取单条记录
     *
     * find.
     * @param int $primary_key 主键编号
     * @return $this
     * @throws ModelException
     * @throws ModelReflectionException
     */
    public function find($primary_key = 0) {
        $result = $this->findByPrimaryKey($primary_key);

        $this->setModelProperty($result);

        return $this;
    }

    /**
     * 根据条件数组查询tbkorderModel，获取多条记录
     *
     * findOneBy.
     * @param array $condition 查询条件
     * @return $this
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     */
    public function findOneBy($condition = []) {
        $result = $this->findRecordBy($condition);

        $this->setModelProperty($result);

        return $this;
    }

    /**
     * 根据条件数组查询tbkorderModel，获取多条记录
     *
     * findBy.
     * @param array $condition 查询条件
     * @return $this
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     */
    public function findBy($condition = []) {
        $count = $this->getCount($condition);
        $total = $count->fetchColumn();

        $this->data = [];
        $tbko_obj = $this->findRecordBy($condition, $this->page, $this->page_size);

        $this->genMeta($total);
        $this->setModelProperty($tbko_obj, true);

        return $this;
    }

    /**
     * 批量插入tbkorderModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function batchInsert() {
        return $this->batchInsertRecord();
    }

    /**
     * 批量删除tbkorderModel
     *
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function batchDelete() {
        $this->batchDeleteRecord();
    }

    /**
     * 生成批量生成update的sql
     *
     * @return bool|string
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function genBatchUpdateSql() {
        return $this->_genBatchUpdateSql();
    }

}
